﻿@using WebSimplicity.Core;
@using WebSimplicity.Data.Blog;
@model WebSimplicity.Data.Blog.ws_Blog_Posts
@{
    ViewBag.Title = "Create";
    ViewBag.BlogState = "active";
}
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@{using (Html.BeginForm("create", "posts", new { section = "content" }, FormMethod.Post, new { @id = "newpostform", @class = "form" }))
  {		
    @Html.ValidationSummary(true)
    <div class="grid_9">
        <div class="block">
            <h3>
                <span>Post Content</span></h3>
            <div class="bcontent">
                <p class="align-left">
                    @Html.LabelFor(model => model.Title)
                    @Html.TextBoxFor(model => model.Title, new { @class = "text full" })
                    @Html.ValidationMessageFor(model => model.Title)</p>
                <p>
                    @Html.TextAreaFor(model => model.PostContent, new { @class = "textarea content full" })
                </p>
                <p>
                    @Html.LabelFor(model => model.PostExcerpt)
                    @Html.TextAreaFor(model => model.PostExcerpt, new { @class = "textarea full" })
                </p>
            </div>
        </div>
    </div>
      
      
    <div class="grid_3">
        <div class="block collapsible">
            <h3>
                <span>Post Settings</span></h3>
            <div class="bcontent">
                <p>
                    @Html.LabelFor(model => model.Slug)
                    @Html.TextBoxFor(model => model.Slug, new { @class = "text full96" })
                    @Html.ValidationMessageFor(model => model.Slug)
                </p><p>
                    @Html.EditorFor(model => model.AllowComments)
                    <label class="inline css_left">
                        Allow Comments</label>
                    @Html.ValidationMessageFor(model => model.AllowComments)
                </p><p>
                    @Html.EditorFor(model => model.Published)
                    <label class="inline css_left">
                        Published</label>
                    @Html.ValidationMessageFor(model => model.Published)
                </p>
                <p>
                    @Html.EditorFor(model => model.PublishDate)
                </p>
            </div>
        </div>
        <div class="block collapsible">
            <h3><span>Post Categories</span></h3>
            <div class="bcontent"><div class="checkbox-list300" id="category-list">
                    @{foreach (ws_Blog_Catgegories category in Categories.GetCategories())
                      {
                      <text><div class="cb-block">
                      <input id="@("cat_" + ShortGuid.Encode(category.CategoryGuid))"  name="@("cat_" + ShortGuid.Encode(category.CategoryGuid))"
                      
                          @{if (category.CategoryGuid == new Guid())
                          {
                              <text>
                              checked="checked"
                               </text>
                          }
                          }
                       type="checkbox" /><label for="@("cat_" + ShortGuid.Encode(category.CategoryGuid))" class="inline css_left">
                        @category.Category</label></div>
                      </text>
                      }                       
                    }
                </div>
                <fieldset><legend>Add New</legend>
                <p><label>Category</label>
                @Html.TextBox("CategoryName", null, new { @class = "text full96" })
                </p><p><label>Slug</label>
                @Html.TextBox("CategorySlug", null, new { @class = "text full96" })
                </p>
                <a id="add-category" class="button css_right"><span><span>
        <img src="@Url.Content("~/content/icons/disk-black.png")" width="16" height="16">
        Add Category</span></span></a>
                </fieldset>
            </div>
        </div>
    </div>
  }
}
@section breadcrumbs{
    <ul>
        <li>@Html.ActionLink("Blog", "blog")</li>
        <li>@Html.ActionLink("Posts", "index","posts")</li>
        <li>Create</li>
    </ul>
    <a class="button submit css_right"><span><span>
        <img src="@Url.Content("~/content/icons/disk-black.png")" width="16" height="16">
        Save</span></span></a> <a href="/admin/content/posts" class="button css_right red"><span>
            <span>
                <img src="@Url.Content("~/content/icons/navigation-180-white.png")" width="16" height="16">
                Cancel</span></span></a>
}
@section scripts{
    <script src="@Url.Content("~/content/modules/ckeditor/ckeditor.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/content/modules/ckeditor/adapters/jquery.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/content/js/functions.js")" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $('#add-category').click(function () {
                $.ajax({
                    url: "/admin/content/categories/jsoncreate",
                    type: 'post',
                    dataType: 'json',
                    data: { Category: $('#CategoryName').val(), Slug: $('#CategorySlug').val() },
                    success: function (cat) {
                        $.each(cat.Categories, function () {
                            var html = '<div class="cb-block"><input type="checkbox" id="cat_' + this.CategoryGuid + '" name="cat_' + this.CategoryGuid + '" checked="checked"/> <label for="cat_' + this.CategoryGuid + '" class="inline css_left">' + this.Category + '</label></div>';
                            $('#category-list').prepend(html);
                        });
                    }
                });
            });
        });
    </script>
}
